package com.cn.jinl.controller;


import com.cn.jinl.api.ISterilizeService;
import com.cn.jinl.domain.Sterilize;
import com.cn.jinl.utils.CommonUtil;
import com.cn.jinl.utils.JsonResponse;
import com.cn.jinl.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/sterilize")
public class SterilizeController {

    @Autowired
    private ISterilizeService sterilizeService;

    @ResponseBody
    @RequestMapping("/getSterilizeList/{frontToken}")
    public JsonResponse<List<Sterilize>> getSterilizeList(QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<Sterilize>> response = new JsonResponse<List<Sterilize>>();
        List<Sterilize> sterilizes = sterilizeService.getSterilizeList(queryForm);
        response.setResult(sterilizes);
        response.setSuccess(true);
        return response;
    }

    @ResponseBody
    @RequestMapping("/getSterilizeHistoryList/{frontToken}")
    public JsonResponse<List<Sterilize>> getSterilizeHistoryList(QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<Sterilize>> response = new JsonResponse<List<Sterilize>>();
        List<Sterilize> sterilizes = sterilizeService.getSterilizeHistoryList(queryForm);
        response.setResult(sterilizes);
        response.setSuccess(true);
        return response;
    }

    @ResponseBody
    @RequestMapping("/addSterilize/{frontToken}")
    public JsonResponse<String> addSterilize(Sterilize sterilize,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = sterilizeService.addSterilize(sterilize);
        return CommonUtil.getResponseData(response,result);
    }

    @ResponseBody
    @RequestMapping("/updateSterilize/{frontToken}")
    public JsonResponse<String> updateSterilize(Sterilize sterilize,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = sterilizeService.updateSterilize(sterilize);
        return CommonUtil.getResponseData(response,result);
    }

    @ResponseBody
    @RequestMapping("/updateCloseSterilize/{frontToken}")
    public JsonResponse<String> updateCloseSterilize(String id,@PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = sterilizeService.updateCloseSterilize(id);
        return CommonUtil.getResponseData(response,result);
    }

    @RequestMapping("/exportSterilizeHistoryList/{frontToken}")
    @ResponseBody
    public JsonResponse<String> exportSterilizeHistoryList(QueryForm queryForm, @PathVariable(value =  "frontToken",required = true) String frontToken) throws Exception{
        JsonResponse<String> response = new JsonResponse<>();
        String result = sterilizeService.exportSterilizeHistoryList(queryForm);
        response.setResult(result);
        response.setSuccess(true);
        return response;
    }


    @ResponseBody
    @RequestMapping("/api/addSterilize")
    public JsonResponse<String> addSterilize(Sterilize sterilize) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = sterilizeService.addSterilize(sterilize);
        return CommonUtil.getResponseData(response,result);
    }

}
